package com.ldk.framework.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.ldk.base.framework.dao.impl.BaseDAO;
import com.ldk.framework.dao.IMenuDAO;
import com.ldk.framework.entity.Menu;

/**
* MenuDAO接口实现类
* @author xiangwl
*/
@Repository
public class MenuDAO extends BaseDAO<Menu> implements IMenuDAO {
	@Override
	public List<Menu> getUserMenus(String dbKey, int roleId) {
		Assert.notNull(roleId);
		try {
			Map<String, Object> parms = new HashMap<String, Object>();
			parms.put("roleId", roleId);
			SqlSession sqlSession = getSqlSession(dbKey);

			return sqlSession.selectList(getSqlName("getUserMenus"), parms);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return null;
	}

	@Override
	public List<Menu> getRoleMenus(String dbKey, int roleId) {
		Assert.notNull(roleId);
		try {
			Map<String, Object> parms = new HashMap<String, Object>();
			parms.put("roleId", roleId);
			SqlSession sqlSession = getSqlSession(dbKey);

			return sqlSession.selectList(getSqlName("getRoleMenus"), parms);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return null;
	}
}
